#!/usr/bin/python
# -*-encoding=utf8 -*-





# 判断是否已经授权
from apps.index.models import IndexUser
from untils.code2session import code2session


def already_authorized(request):
    is_Authorized = False

    if request.session.get('is_Authorized'):
        is_Authorized = True
    return is_Authorized


def get_user(request):
    if not already_authorized(request):
        raise Exception('not authorized request')
    open_id = request.session.get('open_id')
    user = IndexUser.objects.get(open_id=open_id)
    return user


def c2s(appid, code):
    return code2session(appid, code)
